<template>
	<view class="cart-container">
		<my-address></my-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		
		<uni-swipe-action>
			<block v-for="(goods,i) in cart" :key="i">
				<uni-swipe-action-item :options="options" @click="swipeItemClickHandler(goods)">
					<my-goods :goods="goods" :show-radio="true" :showNum="true" @radio-change="radioChangeHandler"
					@num-change="numChangeHandler"></my-goods>
				</uni-swipe-action-item>
			</block>

		</uni-swipe-action>
		
		<mysettle></mysettle>
		
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		computed:{
			...mapState('m_cart',['cart']),
			...mapGetters('m_cart',['total'])
		},
		watch:{
			total(val){
				uni.setTabBarBadge({
					index:2,
					text:val+''
				})
			}
		},
		data() {
			return {
				options:[{
					text:'删除',
					style:{
						backgroundColor:'#C00000'
					}
				}]
			};
		},
		methods:{
			...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
			radioChangeHandler(e){
				// console.log(e)
				this.updateGoodsState(e)
			},
			numChangeHandler(e){
				console.log(e)
				this.updateGoodsCount(e)
			},
			swipeItemClickHandler(goods){
				this.removeGoodsById(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-container{
		padding-bottom: 50px;
	}
.cart-title{
	height: 40px;
	line-height: 40px;
	margin-left: 5px;
	font-size: 14px;
	border-bottom: 1px solid #efefef;
	.cart-title-text{
		margin-left: 10px;
	}
}
</style>
